package com.example.wxchatdemo;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;

public class speackingAdapter extends BaseAdapter {
    private LinkedList<speacking> speackings;
    private Context mContext;
    private String my_id,other_id;
    private  String f_name;
    private  int do_friend_name=1;
    //
    private String left_time,right_time;

    public speackingAdapter(LinkedList<speacking> speackings, Context mContext, String my_id, String other_id, String left_time, String right_time) {
        this.speackings = speackings;
        this.mContext = mContext;
        this.my_id = my_id;
        this.other_id = other_id;
        this.left_time = left_time;
        this.right_time = right_time;
    }

    public speackingAdapter(LinkedList<speacking> speackings, Context mContext, String my_id, String other_id, String left_time, String right_time, String f_name) {

        this.speackings = speackings;
        this.mContext = mContext;
        this.my_id = my_id;
        this.other_id = other_id;
        this.left_time = left_time;
        this.right_time = right_time;
        this.f_name = f_name;
    }

    public speackingAdapter(LinkedList<speacking> speackings, Context mContext, String my_id, String other_id) {
        this.speackings = speackings;
        this.mContext = mContext;
        this.my_id=my_id;
        this.other_id=other_id;
    }
    public speackingAdapter(){}

    @Override
    public int getCount() {
        return speackings.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    //把描述转化为小时
    public String getSimploTime(String arg){
        if (arg==""){
            arg="1647265364027";
        }
        if (null==arg){
            arg="1647265364027";
        }

        Long i = Long.parseLong(arg);
        String format = new SimpleDateFormat(" HH:mm").format(new Date(i));
      //  System.out.println("转化的时间是：="+format);
        return format;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.speacking,parent,false);
        LinearLayout L_left=(LinearLayout) convertView.findViewById(R.id.L_left);
        LinearLayout R_right=(LinearLayout) convertView.findViewById(R.id.R_right);

        TextView left = (TextView) convertView.findViewById(R.id.left);
        TextView right = (TextView) convertView.findViewById(R.id.right);
        ImageView img_left = (ImageView) convertView.findViewById(R.id.img_left);
        ImageView img_right = (ImageView) convertView.findViewById(R.id.img_right);
        //
        TextView left_time=(TextView)convertView.findViewById(R.id.left_time);
        TextView right_time=(TextView)convertView.findViewById(R.id.right_time);


       // System.out.println(other_id+"------"+my_id);
        if (speackings.get(position).getNumber().equals(other_id)){
            img_left.setBackgroundResource(R.mipmap.ic_icon_dog);
            left.setText(speackings.get(position).getContent());
            left_time.setText(getSimploTime(speackings.get(position).getTime()));


            R_right.setVisibility(View.GONE);
//            img_right.setVisibility(View.GONE);
//           right.setTextSize(0);

        }else {
            right.setText(speackings.get(position).getContent());
            img_right.setBackgroundResource(R.mipmap.ic_icon_cow);
            right_time.setText(getSimploTime(speackings.get(position).getTime()));
            L_left.setVisibility(View.GONE);
//            img_left.setVisibility(View.GONE);
//            left.setTextSize(0);

        }
        return convertView;
    }
}
